package com.app.client;

import com.app.ThreadManager;
import com.app.game.other.Player;
import com.app.task.Task;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Client extends Task{
	private ServerHandler handler;
        private int port;
        private String addr;
        private Player player;
        public Client(int port,String addr,Player player){
            this.port = port;
            this.addr = addr;
            this.player = player;
        }
	public Player connect(int port,String addr,Player player){
		try {
			Socket socket = new Socket();
                        socket.connect(new InetSocketAddress(addr, port), 3000);
                        //InputStream is = socket.getInputStream();
			handler = new ServerHandler(socket);
			player.setServerHandler(handler);
                        handler.sendPlayer(player);
                        ThreadManager.getInstance().execute(handler);
                        return player;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
                return null;
                
	}

    @Override
    protected void task() {
        connect(port, addr, player);
        stop();
    }
}
